package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.SidedishmenuPK;
import com.restaurant.service.SidedishmenuPKService;

public class SidedishmenuPKServiceImpl implements SidedishmenuPKService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public SidedishmenuPK addOrModify( SidedishmenuPK objSidedishmenuPK ) {
       return ( SidedishmenuPK ) hibernateTemplate.merge( objSidedishmenuPK );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public SidedishmenuPK deleteRecord( SidedishmenuPK objSidedishmenuPK ) {
       hibernateTemplate.delete( objSidedishmenuPK );
       return objSidedishmenuPK;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public SidedishmenuPK modifyRecord( SidedishmenuPK objSidedishmenuPK ) {
       return ( SidedishmenuPK ) hibernateTemplate.merge( objSidedishmenuPK );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<SidedishmenuPK> loadAll() {
       return (List<SidedishmenuPK>)hibernateTemplate.findByNamedQuery( "SidedishmenuPK.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public SidedishmenuPK loadByPrimaryKey( Long primaryKey ) {
       return (SidedishmenuPK) hibernateTemplate.get( SidedishmenuPK.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public SidedishmenuPK deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<SidedishmenuPK> loadByHql(String query) {
       return ( List<SidedishmenuPK> ) hibernateTemplate.find( query );
   }
}